# -*- coding: utf-8 -*-
# Created by shu2015626 on 2019-10-24
"""
生产分支的配置信息
"""

ALLOWED_HOSTS = ['192.168.235.121', '192.168.235.122']

# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.postgresql',
#         'NAME': 'ptt_app',
#         'USER': 'py_timed_tasks',
#         'PASSWORD': 'ptt123456',
#         'HOST': '127.0.0.1',
#         'PORT': '5432',
#     }
# }

# CELERY_BROKER_URL = 'sentinel://:password@192.168.1.1:26380/1;sentinel://:password@192.168.1.2:26380/1;sentinel://:password@192.168.1.3:26380/1'
# CELERY_BROKER_TRANSPORT_OPTIONS = {'master_name': 'mymaster', 'visibility_timeout': 60 * 60 * 2, 'fanout_prefix': '/1.'}
CELERY_BROKER_URL = 'redis://:ptt123456@192.168.235.121:6379/0'  # 使用Redis作为消息代理
CELERY_BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 60 * 60 * 2, 'fanout_prefix': True}


# 直连redis的相关配置
REDIS_MODE = "single"  # 可以是single, sentinel, cluster的一种
if REDIS_MODE == "single":
    REDIS_SETTINGS_DCT = {
        "redis_host": '192.168.235.121',
        "redis_port": 6379,
        "redis_db_num": 0,
        "redis_passwd": 'ptt123456',
    }
elif REDIS_MODE == "sentinel":
    REDIS_SETTINGS_DCT = {
        "redis_sentinel_servers": [('192.168.235.121', '26377'), ('192.168.235.121', '26378'), ('192.168.235.121', '26379')],
        "redis_master_name": "master_121",
        "redis_db_num": 2,
        "redis_passwd": 'ptt123456',
    }
elif REDIS_MODE == "cluster":
    REDIS_SETTINGS_DCT = {
        "redis_cluster_nodes": [
                                {"host": "127.0.0.1", "port": "8000"},
                                {"host": "127.0.0.1", "port": "8001"},
                                {"host": "127.0.0.1", "port": "8002"},
                                {"host": "127.0.0.1", "port": "8003"},
                                {"host": "127.0.0.1", "port": "8004"},
                                {"host": "127.0.0.1", "port": "8005"},
                                ],
        "redis_passwd": '',
    }

# 自己操作需要操作的key,先定义清楚
REDIS_KEY_DICT = {
    'heartbeat': "str_heartbeat:ptt",  # 用于检测ptt(PyTimedTasks)应用时候还活着
}

# log日志的相关配置
LOG_FILE4PROJ = r"/home/anand/logs/PyTimedTasks/logfiles/py_timed_tasks.log"  # 项目的日志文件
LOG_FILE4TASKS = r"/home/anand/logs/PyTimedTasks/logfiles/tasks.log"  # celery task的日志文件

# ======================= Sentry相关配置 ================================ #
# 是否集成sentry服务
IS_USE_SENTRY = False
DSN = "http://2ce94039b1624234875a5bbc2e9cb8ed@192.168.235.121:9000/17"

if IS_USE_SENTRY:
    import logging
    import sentry_sdk
    # 在settings里这样集成，只能捕获到HTTP Internal Server Error的错误
    from sentry_sdk.integrations.django import DjangoIntegration
    # The integration will automatically report errors from all celery jobs.
    from sentry_sdk.integrations.celery import CeleryIntegration
    # 集成基础的logging功能
    from sentry_sdk.integrations.logging import LoggingIntegration

    sentry_logging = LoggingIntegration(
        level=logging.INFO,  # Capture info and above as breadcrumbs
        event_level=logging.ERROR  # Send errors as events
    )

    sentry_sdk.init(
        dsn=DSN,
        integrations=[
            DjangoIntegration(),  # 只会报告django http相关的错误
            CeleryIntegration(),  # 追回报告celery jobs的任务
            sentry_logging,   # 集成所有logger对象记录的错误
        ]
    )
